package com.zelin.shop.controller;

import com.zelin.common.utils.PageUtils;
import com.zelin.common.utils.R;
import com.zelin.shop.entity.ItemCatEntity;
import com.zelin.shop.service.ItemCatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 商品类目
 *
 * @author LZB
 * @email 2668816865@gmail.com
 * @date 2021-10-26 10:21:00
 */
@RestController
@RequestMapping("shop/itemCat")
public class ItemCatController {
    @Autowired
    private ItemCatService itemCatService;

    /**
     * 功能描述:查询一级分类
     * 返回值:
     * 作者:LZB
     * 时间: 2021/11/3 10:27
     */
    @GetMapping("/findItemCat1")
    public R findItemCat1(){
        List<ItemCatEntity> itemCatEntities = itemCatService.findItemCat1();
        return R.ok().put("list",itemCatEntities);
    }

    /**
     * 功能描述:根据父级id查询二级分类列表
     * 返回值:
     * 作者:LZB
     * 时间: 2021/11/3 11:45
     */
    @GetMapping("/findParentById/{newId}")
    public R findParentById(@PathVariable Long newId){
        return R.ok().put("list",itemCatService.findParentById(newId));
    }


    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = itemCatService.queryPage(params);

        return R.ok().put("page", page);
    }

    @GetMapping("/findItemCats")
    public R findItemCats(){
        System.out.println("00000000000000");
        return R.ok().put("itemCats",itemCatService.list());
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		ItemCatEntity itemCat = itemCatService.getById(id);
        return R.ok().put("itemCat", itemCat);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody ItemCatEntity itemCat){
		itemCatService.save(itemCat);
        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody ItemCatEntity itemCat){
		itemCatService.updateById(itemCat);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		itemCatService.removeByIds(Arrays.asList(ids));
        System.out.println("33333333");
        return R.ok();
    }

}
